package ztc.servlet;

import ztc.common.UserBean;
import ztc.service.DBUsers;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.net.URLEncoder;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * Created by ztc on 16-4-9.下午6:01
 */
public class Login extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String email=request.getParameter("email");
        String password=request.getParameter("password");
        HttpSession session=request.getSession();
        UserBean userBean=new DBUsers().login(email,password);
        if(userBean!=null){
            session.setAttribute("userBean",userBean);
            response.sendRedirect("/qr/issuance.jsp");
        }else{
            response.sendRedirect("/users/login.jsp?msg="+URLEncoder.encode("密码或用户名错误!","utf-8"));
        }
    }
}
